package com.uzai.console.web.exportinfo;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.exportinfo.ExportInfoIdDto;
import com.uzai.console.dto.exportinfo.ExportInfoQuery;
import com.uzai.console.enums.ExportInfoTypeEnum;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.exportinfo.ExportInfoService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.exportinfo.ExportInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件下载
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "文件下载",tags = "系统设置|文件下载")
@ApiSort(29)
@RestController
public class ExportInfoController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(ExportInfoController.class);

    @Autowired
    private ExportInfoService exportInfoService;

    @ApiOperation(value = "分页查询文件下载明细列表", notes = "分页查询文件下载明细列表", response = ExportInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/exportInfo/findExportInfoList")
    public Object findExportInfoList(@RequestBody ExportInfoQuery exportInfoQuery){
        return exportInfoService.findExportInfoList(exportInfoQuery);
    }

    @ApiOperation(value = "查询文件类型下拉列表", notes = "查询文件类型下拉列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/exportInfo/findTypeListSelected")
    public Object findTypeListSelected(){
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        ExportInfoTypeEnum[] exportInfoTypeEnumArr = ExportInfoTypeEnum.values();
        if(exportInfoTypeEnumArr != null && exportInfoTypeEnumArr.length > 0){
            for (ExportInfoTypeEnum exportInfoTypeEnum : exportInfoTypeEnumArr){
                SelectKeyVo selectKeyVo = new SelectKeyVo();
                selectKeyVo.setKey(String.valueOf(exportInfoTypeEnum.getId()));
                selectKeyVo.setValue(exportInfoTypeEnum.getDesc());
                selectKeyVoList.add(selectKeyVo);
            }
        }
        return selectKeyVoList;
    }

    @SystemLogType(model = SystemModelEnum.ExportInfo, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除", notes = "删除")
    @ApiOperationSupport(order = 3)
    @PostMapping("/exportInfo/deleteExportInfo")
    public Object deleteExportInfo(@RequestBody ExportInfoIdDto exportInfoIdDto){
        exportInfoService.deleteExportInfo(exportInfoIdDto);
        return true;
    }

}
